package group.program.Service.impl;

import group.program.Service.DocService;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
@Service
public class DocServiceImpl implements DocService {

    @Override
    public String extractInformation(MultipartFile file) {
        StringBuilder content = new StringBuilder();

        try (InputStream is = file.getInputStream(); HWPFDocument document = new HWPFDocument(is)) {
            WordExtractor extractor = new WordExtractor(document);
            content.append(extractor.getText());
        } catch (IOException e) {
            e.printStackTrace();
            return "Failed to process the file.";
        }

        return content.toString();
    }
}
